const Router = require("@koa/router"); // 引入路由
const router = new Router({ prefix: "/api/admin/" });

const BaseController = require("../controllers/base.controller");
const UserController = require("../controllers/user.controller");

router.get("/", (ctx) => {
  ctx.body = "hello world!";
});

/**
 * 登录注册相关
 */
// 注册
router.post("register", UserController.registerUser);
// 登录
router.post("loginIn", UserController.loginInUser);
// 登出
router.get("logout", UserController.registerUser);

/**
 * 用户信息相关
 */
// 获取用户信息
router.get("user-info", UserController.getUserDetail);

// 根路由兜底处理
router.all("(.*)", async (ctx) => {
  ctx.status = 404;
  ctx.body = BaseController.renderJsonError("请求地址不存在", 404);
});
module.exports = router;
